package com.xj.pattern.adapter.servlet;

import java.util.ArrayList;
import java.util.List;

import com.xj.pattern.adapter.HandlerAdapter;
import com.xj.pattern.adapter.handler.SimpleControllerHandlerAdapter;
import com.xj.pattern.adapter.handler.SimpleServletHandlerAdapter;

public class DispatcherServlet {
	
	private List<HandlerAdapter> handlerAdapters;
	
	public void init(){
		handlerAdapters = new ArrayList<HandlerAdapter>();
		//这里简单处理，直接new
		handlerAdapters.add(new SimpleControllerHandlerAdapter());
		handlerAdapters.add(new SimpleServletHandlerAdapter());
	}
	
	public void doDispatch(String request, String response) throws Exception {
		for (HandlerAdapter ha : this.handlerAdapters) {
			if (request.equals(ha.getClass().getName())) {
				Object mv = ha.handle(request, response, "");
				System.out.println("调用适配器结束");
			}
		}
	}

}
